import { create, update, remove, query } from '../../../framework/service/index';

export default {

  namespace: 'partTimeList',

  state: {
    jobList: [],
  },

  subscriptions: {
    setup({ dispatch, history }) {
      history.listen(location => {
        if(location.pathname === '/part-time-list') {
          dispatch({
            type: 'query',
          })
        }
      })
    },
  },

  effects: {
    *query({ payload }, { call, put, select }) {
      const { code, data, message } = yield call(query, '/api/jobs', {});
      console.log('code', JSON.stringify(code));
      // console.log('data', JSON.stringify(data));
      console.log('message', JSON.stringify(message));
      if (code === 200 && data) {
        yield put({
          type: 'querySuccess',
          payload: {
            jobList: data
          }
        })
      }
    },
  },

  reducers: {
    querySuccess(state, action) {
      return { ...state, ...action.payload };
    },
  }

};
